//
//  LGOrderDetailController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/14.
//

#import "LGOrderDetailController.h"
#import "LGOrderInformationView.h"
#import "LGOrderUserInfoView.h"
@interface LGOrderDetailController ()
/**   */
@property (nonatomic , strong)UIImageView *statusView;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIButton *typeButton;
/**   */
@property (nonatomic , strong)LGOrderUserInfoView *userView;
/**   */
@property (nonatomic , strong)LGOrderInformationView *orderView;

@end

@implementation LGOrderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"订单详情";
    [self.view addSubview:self.statusView];
    [self.statusView addSubview:self.statusLabel];
    [self.view addSubview:self.typeButton];
    [self.view addSubview:self.userView];
    [self.view addSubview:self.orderView];
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.statusView.mas_bottom).offset(viewPix(16));
        make.left.equalTo(self.view).offset(viewPix(16));
        make.right.equalTo(self.view).offset(-viewPix(16));
    }];
    
    [self.orderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userView.mas_bottom).offset(viewPix(16));
        make.left.right.equalTo(self.userView);
    }];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/visit.Visit/appointmentDetail" parameters:@{@"appointment_id":self.appointId} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.userView.dataDic = returnData;
            self.orderView.dataDic = returnData;
            self.statusLabel.text = LGNSString(returnData[@"state_name"]);
            //10-待支付 、 20-已取消 、 30-待接诊 、 31-咨询中 、 40-已完成 、 41-已爽约 、42-未接通 、 50-已退款
            NSString *state = LGNSString(returnData[@"state"]);
            UIImage *image = [UIImage imageNamed:@"订单详情-状态背景1"];
            if([state isEqualToString:@"30"] || [state isEqualToString:@"31"]){
                //未就诊
                image = [UIImage imageNamed:@"订单详情-状态背景1"];
                
            }else if ([state isEqualToString:@"10"]||[state isEqualToString:@"20"]||[state isEqualToString:@"41"]||[state isEqualToString:@"42"]||[state isEqualToString:@"50"]){
                //已取消、已逾期、已过期、未支付、已退款
                image = [UIImage imageNamed:@"订单详情-状态背景3"];
                
            }else{
                //已就诊、已完成
                image = [UIImage imageNamed:@"订单详情-状态背景2"];
            }
            self.statusView.image = image;
//            self.statusView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height/2.0, image.size.width/2.0, image.size.height/2.0, image.size.width/2.0) resizingMode:UIImageResizingModeStretch];
        }
    } error:^(NSError *error) {
        
    }];
}



#pragma mark
#pragma mark ====> 创建控件
-(UIImageView *)statusView{
    if(!_statusView){
        _statusView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(41), viewPix(83))];
    }
    return _statusView;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentLeft lines:1];
        _statusLabel.frame = CGRectMake(viewPix(39), viewPix(31), viewPix(100), viewPix(20));
    }
    return _statusLabel;
}

-(UIButton *)typeButton{
    if(!_typeButton){
        _typeButton = [UIButton buttonWithTitle:@"订单类型：" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@"订单详情-订单类型"];
        _typeButton.frame = CGRectMake(viewPix(16), kMaxY(self.statusView.frame)+viewPix(16), viewPix(250), viewPix(23));
        _typeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _typeButton.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, 0);
    }
    return _typeButton;
}

-(LGOrderUserInfoView *)userView{
    if(!_userView){
        _userView = [[LGOrderUserInfoView alloc]init];
        [_userView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _userView.backgroundColor = [UIColor whiteColor];
    }
    return _userView;
}

-(LGOrderInformationView *)orderView{
    if(!_orderView){
        _orderView = [[LGOrderInformationView alloc]init];
        [_orderView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _orderView.backgroundColor = [UIColor whiteColor];
    }
    return _orderView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
